package org.graduates.webapp.actions.post;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.graduates.webapp.actions.BaseAction;
import org.projects.graduates.domain.Person;
import org.projects.graduates.domain.PostReply;
import org.projects.graduates.domain.TimeTable;
import org.projects.graduates.page.Pager;

import com.opensymphony.xwork2.ActionSupport;

@ParentPackage(value = "web")
@Action(results = { @Result(name = "success", type = "json", params = {
		"includeProperties",
		"total,pageSize,pageNumber, tid, cPerson, cPerson.id, cPerson.showName,"
				+ " postReplies, postReplies\\[\\d+\\]\\.post, postReplies\\[\\d+\\]\\.post.id, postReplies\\[\\d+\\]\\.post.content,postReplies\\[\\d+\\]\\.post.upDate, postReplies\\[\\d+\\]\\.post.who, postReplies\\[\\d+\\]\\.post.who.id, postReplies\\[\\d+\\]\\.post.who.showName,"
				+ "postReplies\\[\\d+\\]\\.replies," +
				"postReplies\\[\\d+\\]\\.replies\\[\\d+\\]\\.content," +
				" postReplies\\[\\d+\\]\\.replies\\[\\d+\\]\\.upDate, " +
				"postReplies\\[\\d+\\]\\.replies\\[\\d+\\]\\.id, " +
				"postReplies\\[\\d+\\]\\.replies\\[\\d+\\]\\.who, " +
				"postReplies\\[\\d+\\]\\.replies\\[\\d+\\]\\.who.id, " +
				"postReplies\\[\\d+\\]\\.replies\\[\\d+\\]\\.who.showName,"
				+ " postReplies\\[\\d+\\]\\.timeTable" }) })
public class GetPostedAction extends BaseAction {

	private static final long serialVersionUID = -8582517493062554391L;

	private long total = 1;

	private long pageSize = 10;

	private long pageNumber = 1;

	private long tid = 0L;

	private List<PostReply> postReplies = new ArrayList<PostReply>();

	private Person cPerson = super.getCurrentPerson();

	public String execute() {

		if (0L == tid) {
			return ActionSupport.INPUT;
		}

		TimeTable tt = TimeTable.get(TimeTable.class, tid);

		if (null == tt) {
			return ActionSupport.INPUT;
		}

		Pager pager = PostReply.getPager(pageNumber, pageSize);
		total = pager.getRowCount();

		postReplies.addAll(PostReply.page(tt, pageNumber, pageSize));

		return ActionSupport.SUCCESS;
	}

	public long getTid() {
		return tid;
	}

	public void setTid(long tid) {
		this.tid = tid;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public long getPageSize() {
		return pageSize;
	}

	public void setPageSize(long pageSize) {
		this.pageSize = pageSize;
	}

	public long getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(long pageNumber) {
		this.pageNumber = pageNumber;
	}

	public Person getcPerson() {
		return cPerson;
	}

	public void setcPerson(Person cPerson) {
		this.cPerson = cPerson;
	}

	public List<PostReply> getPostReplies() {
		return postReplies;
	}

	public void setPostReplies(List<PostReply> postReplies) {
		this.postReplies = postReplies;
	}

}
